<form class="layui-form" action="">
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">人员名称</label>
            <div class="layui-input-inline">
                <input type="tel" name="user_name" lay-verify="required" autocomplete="off" class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">密码</label>
            <div class="layui-input-inline">
                <input type="text" name="pass_word"   autocomplete="off" class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">确认密码</label>
            <div class="layui-input-inline">
                <input type="text" name="pass_word_affirm"  autocomplete="off" class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-form-item">

        <div class="layui-inline">
            <label class="layui-form-label">身份证号</label>
            <div class="layui-input-inline">
                <input type="text" name="card_num" lay-verify="identity" autocomplete="off" value="" class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="submit" class="layui-btn" lay-submit="" lay-filter="addUser">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<script>
    layui.use(['form'], function(){
        var form = layui.form
            , layer = layui.layer;
        //监听提交
        form.on('submit(addUser)', function(data){
            console.log(data.field);
            if(data.field.pass_word.length != 0){
               if(data.field.pass_word != data.field.pass_word_affirm){
                   layer.msg('密码不一致，请确认', {icon: 5});
                   return false;
               }
            }
            $.ajax({
                url: '{:url("/finance/User/ajaxAddUser")}',
                type: 'post',
                dataType: 'json',
                data:{addUserData:data.field},
                beforeSend: function () {
                    layer.load(2);
                },
                complete: function () {
                    layer.closeAll('loading');
                },
                success: function (res) {
                    if(res.code == 1){
                        layer.msg('添加成功', {icon: 1});
                        return false;
                    }
                    layer.alert(res.msg, {icon: 2}); return false;
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    layer.alert('网络失败，请联系管理员', {icon: 2});
                }
            });
            return false;
        });
    });
</script>